const mongoose = require('mongoose');
mongoose.pluralize(null);
const { Schema, model } = mongoose;
const versionKey = { versionKey: false };
const moment = require('moment');
moment.locale('zh-cn');

//管理员账号
const AdminSchema= new Schema({
    mobile:{ //手机号
        type:String,
        unique:true,
        trim:true
    },
    password:{ //密码
        type:String,
        trim:true,
        select:false
    },
    admin_uid:{ //管理员ID
        type:String,
        unique:true,
        default:()=> new Date().getTime()
    },
    avatarUrl:{ //头像
        type:String,
        default:'https://gd-hbimg.huaban.com/d7d4574c9364e191d816322a6e9788f8edd2c7a8527f-DDR4Ai_fw1200webp'
    },
    nickname:{ //昵称
        type:String,
        default:'管理员',
        trim:true
    },
},versionKey)

//每日推荐
const DaiyrecomSchema = new Schema({
    imageUrl:String,
    title:String,
    address:String,
    color:String,
    time:{
        type:String,
        default:()=>moment().utcOffset(8).format('YYYY-MM-DD HH:mm:ss'), //自动获取时间
    },
    timestamp:{
        type:Number,
        default:()=>moment().unix() //获取时间戳
    }
},versionKey)

//中国省市数据
const ChcitySchema =  new Schema({
    cityName:String,
},versionKey)
const provinceSchema = new Schema({
    provinceName:String,
    citys:{
        type:[ChcitySchema]
    }
},versionKey)

//上传四个推荐游记表
const FourTravelSchema = new Schema({
    imageUrl:String, //封面图
    travel_id:{  //关联游记ID
        type:mongoose.Types.ObjectId,
        ref:'article',
        required:true },
        time:{
            type:String,
            default:()=>moment().utcOffset(8).format('YYYY-MM-DD HH:mm:ss'), //自动获取时间
        },
        timestamp:{
            type:Number,
            default:()=>moment().unix() //获取时间戳
        }
},versionKey)



module.exports = {
    modelAdministrator:model('administrator',AdminSchema),
    modelDailyrecom:model('dailyrecom',DaiyrecomSchema),
    provinceSchema:model('province',provinceSchema),
    modelFourTravel:model('fourtravel',FourTravelSchema)
}